﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLL.Util;
using LDSP.BRL;

namespace EmailService
{
    public class MailManager
    {
        public void Run()
        {
            Email mail = new Email();

            //查找所有到期未发送的mail.
            IList<Email> mails = mail.GetUnSentMail();
            foreach (Email m in mails)
            {
                if (m.PlanSendDate < DateTime.Now
                    && !string.IsNullOrEmpty(m.Bcc))
                {
                    MailSender.SendMail(new List<string>() { m.Bcc }, m.Subject, m.Content, new List<string>(), new List<string>());
                    m.IsSent = true;
                    m.SendDate = DateTime.Now;
                    m.Update();
                }
            }
        }
    }
}
